package com.ruoyi.caipiao.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.Executors;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

/**
 * @author wangcen
 * @date 2025/7/5 21:49
 */
@Configuration
public class MyThreadPoolConfig {
    static int coreCount = Runtime.getRuntime().availableProcessors();//核心数

    @Bean("threadPoolExecutor1")
    public ThreadPoolExecutor threadPoolExecutor1() {
        return new ThreadPoolExecutor(coreCount -1,
                coreCount -1,
                10,
                TimeUnit.SECONDS,
                new ArrayBlockingQueue<>(5000),
                Executors.defaultThreadFactory(),
                new ThreadPoolExecutor.CallerRunsPolicy());
    }
}
